<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>上传文件</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <style>
        body {
            background: linear-gradient(-45deg, #e9e2f3, #d4c9e8, #d1c9ec);
            background-size: 400% 400%;
            animation: gradient 8s ease infinite;
            min-height: 100vh;
            padding: 2rem 0;
            margin: 0;
        }
        @keyframes gradient {
            0% { background-position: 0% 50%; }
            50% { background-position: 100% 50%; }
            100% { background-position: 0% 50%; }
        }
        .card {
            background-color: rgba(255, 255, 255, 0.9);
            border-radius: 12px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
            backdrop-filter: blur(5px);
            padding: 2rem;
            max-width: 600px;
            margin: 0 auto;
        }
        .card-title {
            color: #333;
            font-weight: 700;
            margin-bottom: 1.5rem;
            position: relative;
            padding-bottom: 0.5rem;
            text-align: center;
        }
        .card-title::after {
            content: '';
            width: 50px;
            height: 3px;
            background-color: #8ab4f8;
            position: absolute;
            bottom: 0;
            left: 50%;
            transform: translateX(-50%);
        }
        .form-group {
            margin-bottom: 1.5rem;
        }
        .form-label {
            color: #666;
            font-weight: 500;
            margin-bottom: 0.5rem;
        }
        .file-upload-area {
            border: 2px dashed #eee;
            border-radius: 8px;
            padding: 3rem 2rem;
            text-align: center;
            transition: border-color 0.3s ease;
            cursor: pointer;
            margin-bottom: 1.5rem;
        }
        .file-upload-area:hover {
            border-color: #8ab4f8;
        }
        .file-icon {
            color: #8ab4f8;
            font-size: 3rem;
            margin-bottom: 1rem;
        }
        .file-tip {
            color: #999;
            font-size: 0.9rem;
            margin-top: 0.5rem;
        }
        #fileInput {
            display: none;
        }
        .btn-group {
            display: flex;
            justify-content: center;
            gap: 1rem;
            margin-top: 1rem;
        }
        .btn {
            padding: 0.7rem 1.5rem;
            border-radius: 25px;
        }
        .message {
            animation: fadeIn 0.5s ease-in-out;
            text-align: center;
            margin-bottom: 1rem;
        }
        .success-message { color: #198754; }
        .error-message { color: #dc3545; }
        @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
        #selectedFileName {
            color: #333;
            font-weight: 500;
        }
    </style>
</head>
<body>
<div class="card">
    <h3 class="card-title">上传文件</h3>

    <!-- 提示信息 -->
    <div th:if="${successMsg != null}" class="message success-message" th:text="${successMsg}"></div>
    <div th:if="${errorMsg != null}" class="message error-message" th:text="${errorMsg}"></div>

    <!-- 文件上传表单 -->
    <form th:action="@{/admin/content/file/upload}" method="post" enctype="multipart/form-data">
        <div class="form-group">
            <label class="form-label">选择文件</label>
            <!-- 自定义文件上传区域 -->
            <div class="file-upload-area" onclick="document.getElementById('fileInput').click()">
                <i class="bi bi-cloud-upload file-icon"></i>
                <p>点击或拖拽文件到此处上传</p>
                <p id="selectedFileName" th:text="${selectedFileName}"></p>
                <p class="file-tip">支持格式：docx、pdf、png、jpg 等，单个文件大小不超过10MB</p>
            </div>
            <!-- 隐藏原生文件选择框 -->
            <input type="file" id="fileInput" name="file" accept=".docx,.pdf,.png,.jpg,.jpeg,.xls,.xlsx" onchange="showFileName(this)">
        </div>

        <div class="btn-group">
            <button type="submit" class="btn btn-primary" id="uploadBtn" disabled>上传文件</button>
            <a href="/admin/content/file/list" class="btn btn-secondary">取消返回</a>
        </div>
    </form>
</div>

<!-- 引入图标库 -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
    // 显示选中的文件名
    function showFileName(input) {
        const fileNameElement = document.getElementById('selectedFileName');
        const uploadBtn = document.getElementById('uploadBtn');
        if (input.files.length > 0) {
            fileNameElement.textContent = `已选择：${input.files[0].name}`;
            uploadBtn.disabled = false; // 选中文件后启用上传按钮
        } else {
            fileNameElement.textContent = '';
            uploadBtn.disabled = true;
        }
    }
</script>
</body>
</html>